package com.ruoyi.project.exam.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.exam.domain.RepoModel;
import com.ruoyi.project.exam.service.IRepoService;
import com.ruoyi.project.system.dict.domain.DictType;
import com.ruoyi.project.system.notice.domain.Notice;
import com.ruoyi.project.system.notice.service.INoticeService;

/**
 * 题库管理
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/exam/repo")
public class RepoController extends BaseController {

	private String prefix = "exam/repo";

	@Autowired
	private IRepoService repoService;

	@RequiresPermissions("exam:repo:view")
	@GetMapping()
	public String repo() {
		return prefix + "/repo";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("exam:repo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(RepoModel model) {
		startPage();
		List<RepoModel> list = repoService.selectRepoList(model);
		return getDataTable(list);
	}

	/**
	 * 新增
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存
	 */
	@RequiresPermissions("exam:repo:add")
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(RepoModel model) {
		return toAjax(repoService.insertRepo(model));
	}

	/**
	 * 修改
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap) {
		mmap.put("model", repoService.selectRepoById(id));
		return prefix + "/edit";
	}

	/**
	 * 修改保存
	 */
	@RequiresPermissions("exam:repo:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(RepoModel model) {
		return toAjax(repoService.updateRepo(model));
	}

	/**
	 * 删除
	 */
	@RequiresPermissions("exam:repo:remove")
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(repoService.deleteRepoByIds(ids));
	}
	 /**
     * 校验唯一
     */
	@PostMapping("/checkCodeUnique")
	@ResponseBody
	public String checkCodeUnique(RepoModel model) {
		return repoService.checkCodeUnique(model);
	}
	
	/**
	 * 考试统计
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/quDetail/{id}")
	public String quDetail(@PathVariable("id") String id, ModelMap mmap) {
		mmap.put("repoId", id);
		mmap.put("repoList", repoService.selectAll());
		return  "exam/qu/qu";
	}

}
